package assignment1;
import java.util.LinkedList;


public class DataItem {

	
	private String dData; // Key to compare
	
	private LinkedList<String> listWord;  // Array list of words item
		
	public String getdData() {
		return dData;
	}

	public void setdData(String dData) {
		this.dData = dData;
	}

	public LinkedList<String> getListWord() {
		return listWord;
	}

	public void setListWord(LinkedList<String> listWord) {
		this.listWord = listWord;
	}

	public DataItem(String _key)  // constructor           
	{ 
		listWord = new LinkedList<String>();
		dData = _key;
	}
	
	private Boolean IsWordExist(String word){ // Test if new word is exist in list of words
		for (String s : getListWord()){
			if(s.compareTo(word) == 0){
				return true;
			}
		}
		return false;
	}
	
	public void AddWord(String word){
		
		if(IsWordExist(word)){return;}

		listWord.add(word);
	}
	
	
	public String displayItem()   // display items           
	{ 
		String result ="With key "+ dData+": ";
		
		for(String s : listWord){
			result = result+" " +s;
		}
		
		return result + " has "+listWord.size()+" words \n";
	
	}    
	 
}// end class DataItem    

